package kingone.phone_store_spring_practice.util;

import kingone.phone_store_spring_practice.vo.ResultVO;

/*此处建立工具类的目的是：为了处理将data的数据+code+msg集体处理成泛型类的ResultVO*/
public class ResultVOUtil {
    public static ResultVO success(Object data){
        //将ResultVO所需要的属性值填充进去
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(0);
        resultVO.setMsg("成功");
        resultVO.setData(data);

        return resultVO;
    }

    //失败时，返回的data对象为空，并提示错误消息
    public static ResultVO error(String error){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(0);
        resultVO.setMsg(error);
        resultVO.setData(null);

        return resultVO;
    }
}
